package cn.iocoder.yudao.module.erp.dal.mysql.business.sequence;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.business.sequence.vo.SequencePageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.business.sequence.SequenceDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 单据编号 Mapper
 *
 * @author maxuxu
 */
@Mapper
public interface SequenceMapper extends BaseMapperX<SequenceDO> {

    default PageResult<SequenceDO> selectPage(SequencePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SequenceDO>()
                .likeIfPresent(SequenceDO::getSeqName, reqVO.getSeqName())
                .eqIfPresent(SequenceDO::getSeqPartition, reqVO.getSeqPartition())
                .eqIfPresent(SequenceDO::getSeqNextValue, reqVO.getSeqNextValue())
                .orderByDesc(SequenceDO::getId));
    }

    default SequenceDO selectBySeqNamed(String seqName){
        return selectOne(new LambdaQueryWrapperX<SequenceDO>().eq(SequenceDO::getSeqName, seqName));
    }
}